package leetCode;

import java.util.Arrays;

public class t383m2 {
    public static void main(String[] args) {

        System.out.println(new Solutiont383m2().canConstruct("abccd","aeeebbccdef"));
    }
}
class Solutiont383m2 {
    public boolean canConstruct(String ransomNote, String magazine) {
        char[] Rchars = ransomNote.toCharArray();
        Arrays.sort(Rchars);
        char[] Mchars = magazine.toCharArray();
        Arrays.sort(Mchars);
        int RIndex=0;
        int MIndex=0;
        while (RIndex<Rchars.length&&MIndex<Mchars.length){
            if (Rchars[RIndex]==Mchars[MIndex]){
                RIndex++;
                MIndex++;
            }else {
                MIndex++;
            }
        }
        return RIndex==Rchars.length;
    }
}